package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.crowdsource.AddressTaxRateFormBean;
import com.info.zhiduoduo.admin.model.formbean.crowdsource.SaveTaxRateFormBean;
import com.info.zhiduoduo.admin.model.formbean.invoice.ApprovalScreenshotFromBean;
import com.info.zhiduoduo.admin.model.formbean.invoice.EditRemarkFormBean;
import com.info.zhiduoduo.admin.model.formbean.maker.MakerListFormBean;
import com.info.zhiduoduo.admin.model.formbean.taxer.*;
import com.info.zhiduoduo.admin.service.TaxerService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.core.service.CoreTaxerService;
import com.info.zhiduoduo.core.service.common.DocService;
import com.info.zhiduoduo.repository.dto.maker.StudioBriefDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerCompanyListDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerInvoiceDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerPaymentDto;
import com.info.zhiduoduo.repository.entity.invoice.Invoice;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInviteCode;
import com.info.zhiduoduo.repository.entity.taxer.TaxerInvoice;
import com.info.zhiduoduo.repository.entity.taxer.TaxerPayment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Api(tags = " 接口")
@RestController
@RequestMapping("/taxer")
public class TaxerController {

	@Autowired
	TaxerService taxerService;
	@Autowired
	DocService docService;
	@Autowired
	CoreTaxerService coreTaxerService;

	@ApiOperation(value = "查询已到期 创客", tags = "个人")
	@PostMapping("/taxerStudioExpireList")
	public SmartResult<StudioBriefDto> taxerStudioExpireList(@RequestBody BaseSimpleFormBean<MakerListFormBean> formBean) {
		return taxerService.taxerStudioExpireList(formBean);
	}
	@ZddLog( name = "到期 创客设置续约")
	@ApiOperation(value = "到期 创客设置续约")
	@PostMapping("/taxerStudioRenewal")
	public SmartResult taxerStudioRenewal(@RequestBody @Validated 	BaseSimpleFormBean<TaxerStudioRenewalFormBean> formBean) {
		return taxerService.taxerStudioRenewal(formBean);
	}

	// ***************************************  支付 ******************************** //

	@ZddLog( name = "创建 支付记录")
	@ApiOperation(value = "创建 支付记录", tags = " 支付")
	@PostMapping("/createPayment")
	public SmartResult createPayment(@Valid @RequestBody BaseSimpleFormBean<CreateTaxerPaymentFormBean> formBean) {
		return taxerService.createPayment(formBean);
	}

	@ApiOperation(value = " 支付记录列表", tags = " 支付")
	@PostMapping("/paymentList")
	public SmartResult<TaxerPaymentDto> getPaymentList(@RequestBody BaseSimpleFormBean<PaymentListFormBean> formBean) {
		return taxerService.getPaymentList(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE, name = "确认支付完成", entities = @LogEntity(entity = TaxerPayment.class, parameters =
	@LogParameter(fields = "payid",parameters = "formBean.reqdata.payid")))
	@ApiOperation(value = "确认支付完成", tags = " 支付")
	@PostMapping("/confirmPayment")
	public SmartResult confirmPayment(@RequestBody BaseSimpleFormBean<TaxerPaidVerifyFormBean> formBean) {
		return taxerService.confirmPayment(formBean);
	}

	// ***************************************  发票 ******************************** //

	@ApiOperation(value = "获取发票列表", tags = " 发票")
	@PostMapping("/invoiceList")
	public SmartResult<TaxerInvoiceDto> getInvoiceList(@RequestBody BaseSimpleFormBean<TaxerInoviceListFormBean> formBean) {
		return taxerService.getInvoiceList(formBean);
	}

	@ApiOperation(value = "导出发票列表", tags = " 发票")
	@GetMapping("/exportTaxerInvoiceList")
	public void exportTaxerInvoiceList(HttpServletResponse response,TaxerInoviceListFormBean formBean){
		taxerService.exportTaxerInvoiceList(response,formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE, name = "编辑 发票", entities = @LogEntity(entity = TaxerInvoice.class, parameters =
	@LogParameter(fields = "invoiceid",parameters = "formBean.reqdata.invoiceid")))
	@ApiOperation(value = "编辑 发票", tags = " 发票")
	@PostMapping("/editInvoice")
	public SmartResult editInvoice(@RequestBody BaseSimpleFormBean<EditTaxerInvoiceFormBean> formBean) {
		return taxerService.editInovice(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE, name = "确认开票", entities = @LogEntity(entity = TaxerInvoice.class, parameters =
	@LogParameter(fields = "invoiceid",parameters = "formBean.reqdata.invoiceid")))
	@ApiOperation(value = "确认开票", tags = " 发票")
	@PostMapping("/confirmInvoice")
	public SmartResult confirmInvoice(@RequestBody BaseSimpleFormBean<ConfirmTaxerInvoiceFormBean> formBean) {
		return taxerService.confirmInvoice(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE, name = "编辑 发票", entities = @LogEntity(entity = TaxerInvoice.class, parameters =
	@LogParameter(fields = "invoiceid",parameters = "formBean.reqdata.invoiceid")))
	@ApiOperation(value = "编辑发票备注", tags = " 发票")
	@PostMapping("/editInvoiceRemark")
	public SmartResult editInvoiceRemark(@Valid @RequestBody BaseSimpleFormBean<EditTaxerInvoiceRemarkFormBean> formBean) {
		return taxerService.editInvoiceRemark(formBean);
	}

	@ApiOperation(value = "下载发票项目合同", tags = " 发票")
	@GetMapping("/downloadContract")
	public void downloadContract(HttpServletRequest request, HttpServletResponse response, @RequestParam int invoiceid) {
		docService.downloadTaxerInvoiceContract(request, response, invoiceid);
	}

	@ZddLog(type = ZddLogType.UPDATE,name = "保存发票凭证",entities = @LogEntity(entity = TaxerInvoice.class,parameters =
	@LogParameter(fields = "invoiceid",parameters = "formBean.reqdata.invoiceid")))
	@ApiOperation("保存发票凭证")
	@PostMapping("/saveInvoiceReceiptImg")
	public SmartResult saveInvoiceReceiptImg(@RequestBody BaseSimpleFormBean<ReceiptImgFormBean> formBean) {
		return taxerService.saveInvoiceReceiptImg(formBean);
	}

	// *********************************   邀请码 ******************************

	@ApiOperation("获取 邀请码列表")
	@PostMapping("/inviteCodeList")
	public SmartResult getTaxerInviteCodeList(@RequestBody BaseSimpleFormBean<String> formBean) {
		return taxerService.getTaxerInviteCodeList(formBean);
	}

	@ZddLog(name = "新增或编辑邀请码")
	@ApiOperation("新增或编辑邀请码")
	@PostMapping("/addEditTaxerInviteCode")
	public SmartResult addEditInviteCode(@Valid @RequestBody BaseSimpleFormBean<AddEditInviteCodeFormBean> formBean) {
		return taxerService.addEditInviteCode(formBean);
	}

	@ZddLog(type = ZddLogType.DELETE,name = "删除邀请码",entities = @LogEntity(entity = TaxerInviteCode.class,parameters =
	@LogParameter(fields = "id",parameters = "formBean.reqdata")))
	@ApiModelProperty("删除邀请码")
	@PostMapping("/delInviteCode")
	public SmartResult delInviteCode(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.delInviteCode(formBean);
	}


	@ApiOperation("获取 收藏的企业列表")
	@PostMapping("/queryCompanyList")
	public SmartResult<TaxerCompanyListDto> getTaxerCompanyList(@RequestBody BaseSimpleFormBean<TaxerCompanyListFormBean> formBean) {
		return taxerService.queryCompanyList(formBean);
	}

	@ApiOperation("导出 收藏的企业列表")
	@GetMapping("/exportCollectTaxerList")
	public void exportCollectTaxerCompanyList( TaxerCompanyListFormBean  baseSimpleFormBean  , HttpServletResponse response  ){
		taxerService.exportCollectTaxerCompanyList( response , baseSimpleFormBean );
	}


	@ApiOperation("导入历史成交的 项目")
	@PostMapping("/importDealedProject")
	public SmartResult importDealedProject(@RequestParam("file") MultipartFile file, @RequestParam("userid") int userid,
										   @RequestParam("type") int type) {
		return taxerService.importDealedProject(file,userid,type);
	}

	@ZddLog(type = ZddLogType.DELETE,name = "删除导入历史成交的 项目",entities = @LogEntity(entity = TaxerInvoice.class))
	@ApiOperation("删除导入历史成交的 项目")
	@PostMapping("/deleteImportDealedProject")
	public SmartResult deleteImportDealedProject(@RequestBody BaseSimpleFormBean<Object[]> formBean) {
		return taxerService.deleteImportDealedProject(formBean);
	}

	@ApiOperation("根据城市id和档位数值添加档位")
	@PostMapping("/insertAddressTaxRate")
	public SmartResult insertAddressTaxRate(@RequestBody BaseSimpleFormBean<AddressTaxRateFormBean> formBean) {
		return taxerService.insertAddressTaxRate(formBean);
	}

	@ApiOperation("根据城市id查询档位")
	@PostMapping("/selectAddressTaxRate")
	public SmartResult selectAddressTaxRate(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.selectAddressTaxRate(formBean);
	}

	@ZddLog(name = "添加或修改创客费率")
	@ApiOperation("添加或修改创客费率")
	@PostMapping("/insertOrUpdateTaxRate")
	public SmartResult insertOrUpdateTaxRate(@RequestBody BaseSimpleFormBean<SaveTaxRateFormBean> formBean) {
		return taxerService.insertOrUpdateTaxRate(formBean);
	}

	@ApiOperation("根据Userid查询创客费率")
	@PostMapping("/selectTaxRateListByUserid")
	public SmartResult selectTaxRateByList(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return taxerService.selectTaxRateByList(formBean);
	}

	@GetMapping("/fixSupplementProjectInvoice")
	public SmartResult fixSupplementProjectInvoice() {
		taxerService.fixSupplementProjectInvoice();
		return SmartResult.success();
	}

	@GetMapping("/fixOldServiceCharge2TaxFee")
	public SmartResult fixOldServiceCharge2TaxFee() {
		taxerService.fixOldServiceCharge2TaxFee();
		return SmartResult.success();
	}
	/**
	 *  发票编辑发票备注
	 */
	@ZddLog(type = ZddLogType.UPDATE, name = " 发票编辑发票备注", entities = @LogEntity(entity = TaxerInvoice.class, parameters =
	@LogParameter(parameters = "formBean.reqdata.id")))
	@PostMapping("/editRemark")
	public SmartResult editRemark(@RequestBody BaseSimpleFormBean<EditRemarkFormBean> formBean) {
		return taxerService.editRemark(formBean);
	}


	@ApiOperation("上传30万审批截图")
	@PostMapping("/approvalScreenshot")
	public SmartResult approvalScreenshot(@RequestBody BaseSimpleFormBean<ApprovalScreenshotFromBean> formBean) {
		return taxerService.approvalScreenshot(formBean.getReqdata());
	}
}
